﻿using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Trippy.CollidableGameComponents;
using Trippy.CollidableGameComponents.Agents;
using Trippy.Levels;

namespace Trippy.Abilities
{
    public class Sprint : Ability
    {
        public Sprint(Level level) : base (level)
        {
            name = "Sprint";
            icon = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Ability Icons/sprint");
        }
        public override void OnActivate()
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Grounded)
                State = AbilityState.Active;
            base.OnActivate();
        }

        public override void OnMoveLeft(float elapsedTime)
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Grounded && State == AbilityState.Active)
                CurrentLevel.Hero.Velocity = new Vector2(CurrentLevel.Hero.Velocity.X - elapsedTime * 200.0f, CurrentLevel.Hero.Velocity.Y);
            base.OnMoveLeft(elapsedTime);
        }

        public override void OnMoveRight(float elapsedTime)
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Grounded && State == AbilityState.Active)
                CurrentLevel.Hero.Velocity = new Vector2(CurrentLevel.Hero.Velocity.X + elapsedTime * 200.0f, CurrentLevel.Hero.Velocity.Y);
            base.OnMoveRight(elapsedTime);
        }


        public override void OnRelease()
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Grounded)
                State = AbilityState.Available;
            base.OnRelease();
        }
        public override void OnLand()
        {
            if (CurrentLevel.CurrentKeyboardState.IsKeyUp(CurrentLevel.Game.action))
                State = AbilityState.Available;
            if (CurrentLevel.CurrentKeyboardState.IsKeyDown(CurrentLevel.Game.action))
                State = AbilityState.Active;
            base.OnLand();
        }

        public override void OnAir()
        {
            State = AbilityState.Unavailable;
            base.OnAir();
        }

        public override void OnAdd()
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Jumping)
                State = AbilityState.Unavailable;
            base.OnAdd();
        }
    }
}
